package org.september.pisces.region;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.september.pisces.module.api.PiscesModule;
import org.september.pisces.module.api.WebMenu;
import org.september.pisces.region.controller.RegionController;
import org.september.pisces.region.entity.CurrentRegion;
import org.september.smartdao.CommonDaoHolder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;


/**
 * 标注service，用于主工程发现插件模块
 * @author yexinzhou
 *
 */
@Configuration
@ComponentScan(basePackageClasses = RegionModule.class)
public class RegionModule implements PiscesModule {

	public static final String 区域管理="区域管理";
	
	private static Map<String,List<WebMenu>> moduleMap = new HashMap<>();
	static {
		List<WebMenu> menus1 = new ArrayList<>();
		menus1.add(new WebMenu("区域管理-区域树", RegionController.RegionTree_Page, "layui-icon-component")
				.addPermission("页面", PiscesRegionPermission.区域树.getUrls())
				.addPermission("编辑", PiscesRegionPermission.编辑区域.getUrls())
				.addPermission("删除", PiscesRegionPermission.删除区域.getUrls())
				.addPermission("初始化", PiscesRegionPermission.初始化区域.getUrls()));
		
		menus1.add(new WebMenu("区域管理-区域列表", RegionController.Region_List_Page, "layui-icon-component")
				.addPermission("列表页面", PiscesRegionPermission.区域列表.getUrls()));
		moduleMap.put(区域管理, menus1);
	}
	
	public static List<WebMenu> getWebMenus(String moduleName) {
		return moduleMap.get(moduleName);
    }
	
	public RegionModule(){
		System.out.println(this.getClass().getName()+" init..");
	}

	public String[] getMyBatisMapperLocation() {
		return new String[] {"classpath:"+this.getClass().getPackageName().replace(".", "/")+"/mapper/*.xml"};
	}
	
	public String[] getEntityPackages() {
		return new String[] {this.getClass().getPackageName()+".entity"};
    }
	
	public void init() {
		CurrentRegion cr = new CurrentRegion();
		CurrentRegion po = CommonDaoHolder.getCommonDao().getByExample(cr);
		if(po==null) {
			cr.setRegionId(100000L);
			cr.setZipCode(0L);
			cr.setStartFlag(1);
			CommonDaoHolder.getCommonDao().save(cr);
		}
    }
}
